'use strict';
/**
*Dictionary Object class
*auth:lww
*version:1.0
*date:2019-06-10
*/
function Word (ids, wordName, wordValue, data){      
    this.id = ids;
    this.name = wordName;
    this.label = wordName;
    this.value = wordValue;   
    this.data = data;   
    this.view = null;
    this.child = null;
}
Word.prototype.getId= function(){
    return this.id;
};
Word.prototype.getName = function(){
    return this.name;
};
Word.prototype.getValue = function(){
    return this.value;
};
Word.prototype.getData = function(){
    return this.data;
};
Word.prototype.getLabel = function(){
    return this.label;
};
Word.prototype.setLabel = function(lbl){
    this.label = lbl;
    return this;
};
Word.prototype.getView = function(){
    return this.view;
};
Word.prototype.setView = function(v){
    this.view = v;
    return this;
};
Word.prototype.getChild = function(){
    return this.child;
};
Word.prototype.setChild = function(dictionary){
    this.child = dictionary;
    return this;
};
/**
 * Dictionary
 */
function Dictionary (dictionaryName){   
    this.version = "1.0";
    this.name = dictionaryName;
    this.wordlist = new Array();
}
Dictionary.prototype.addWord = function(w){
    if(this.wordlist == null){
        this.wordlist = new Array();
    }
    this.wordlist[this.wordlist.length] = w;
    return this;
};
Dictionary.prototype.getWord = function(index){
    if(this.wordlist == null){
       return null;
    }    
    if(index >= 0 && index < this.wordlist.length){
        return this.wordlist[index];
    }
    else{
        return null;
    }
};
Dictionary.prototype.findFirstByValue = function(v){
    if(this.wordlist == null){
       return null;
    }    
    var word  = null;
    for(var w of this.wordlist){
        if(w.value === v){
            word = w;
            break;
        }  
    }   
    return word;
};
Dictionary.prototype.findFirstByName = function(name){
    if(this.wordlist == null){
       return null;
    }    
    var word  = null;
    for(var w of this.wordlist){       
        if(w.name === name){
            word = w;
            break;
        }  
    }   
    return word;
};
Dictionary.prototype.forEach = function(each){
    if(this.wordlist == null){
        return;
    }
    for(var w of this.wordlist){  
        var ret = each(w);
        if(ret){
            break;
        }
    }    
};

markscript("Dictionary");
//end Dictionary.js